/*
 * @Author: AskMeWhy
 * @Date: 2020-09-14 16:48:31
 * @Last Modified by: AskMeWhy
 * @Last Modified time: 2021-02-04 17:50:00
 */
import Vue from "vue";
import { merge } from "@/utils";
import ComponentTemplate from "./form.vue";
const VueComponent = Vue.extend(ComponentTemplate);

export const dialogForm = (option: any) => {
    const vm: any = new VueComponent().$mount();
    vm.title = option.title || vm.title;
    vm.filterable = option.filterable || vm.filterable;
    vm.filterMethod = option.filterMethod || vm.filterMethod;
    vm.checkStrictly = option.checkStrictly || vm.checkStrictly;
    vm.value = merge(true, [], option.value);
    vm.disabledValue = merge(true, [], option.disabledValue);
    vm.options = merge(true, [], option.options);

    vm.$on("onchange", (item: any) => {
        if (option && option.onChange) option.onChange(vm, item);
    });
    vm.$on("sure", (model: any) => {
        if (option && option.sure) option.sure(vm, model);
    });
    vm.$on("onclose", (model: any) => {
        if (option && option.close) option.close(vm, model);
    });
    vm.show = true;
    return vm;
};
